package gruppe7.data;

import gruppe7.db.DBAccess;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class DBUserProvider implements UserProvider {

	public void addUser(User newUser, PasswordHash hash) throws UserException, ProviderException {
		throw new UserException("Ikke implementeret");
	}

	public User authenticateUser(String username, PasswordHash hash) throws UserException, ProviderException {
		
		try {
			Connection conn = DBAccess.getInstance().getConnection();
			String sql = "SELECT FROM users WHERE userName = ? AND password = ?";
			
			PreparedStatement stmt = conn.prepareStatement(sql);
			stmt.setString(1, username);
			stmt.setString(2, hash.getHash());
			
			ResultSet rs = stmt.executeQuery();
			
			rs.close();
			conn.close();
			
			return null;
		}
		
		catch (Exception e) {
			throw new UserException(e);
		}
	}

}
